import store from '@/store/index'
import quinn from '@/utils/quinn'
import { IMG_HOST } from '@/assets/js/define.js'
import {
  _h,
  AFTERSALE_TAG,
  areaColumn,
  colorBlue,
  colorGreen,
  colorGrey,
  colorOrange,
  colorRed,
  createdColumn,
  EXTRA_ORDER_STATUS,
  EXTRA_ORDER_TAG_STATUS,
  EXTRA_TAG,
  FINANCE_TYPE_STATUS,
  FINANCE_TYPE_TAG_STATUS,
  goodsFeeColumn,
  hotelFeeColumn,
  INOUT_STATUS,
  INOUT_TAG_STATUS,
  installFeeColumn,
  inventoryColumn,
  ORDER_STATUS,
  ORDER_TAG_STATUS,
  otherFeeColumn,
  PRODUCT_STATUS,
  sortIndex,
  statusRender,
  statusRenderMap,
  trafficFeeColumn,
  updatedColumn,
  widthdf,
  widthlg,
  widthsm,
  widthssl,
  widthxl,
  widthxs,
  widthxsl,
  widthxxl,
} from './params'

const { authority = [] } = quinn.getStorage('userData') || {}

const { userName = [] } = quinn.getStorage('userData') || {}
const getOrderColumns = () => {
  let res = []
  if (authority.includes(105))
    res = [
      {
        label: '成本价',
        prop: 'costPrice',
        fixed: 'right',
        minWidth: widthdf,
      },
      { label: '利润', prop: 'profit', fixed: 'right', minWidth: widthdf },
    ]
  return res
}

const _imgRender = function (h, scope) {
  const { column, row } = scope
  const value = row[column.property]
  let imgList = []
  if (Array.isArray(value)) {
    try {
      imgList = value.filter((e) => e).map((e) => IMG_HOST + e)
    } catch (e) {}
  } else if ((value || '').includes(','))
    imgList = value
      .split(',')
      .filter((e) => e)
      .map((e) => IMG_HOST + e)
  else if (value) imgList.push(IMG_HOST + value)
  return imgList.length
    ? h(
        'el-image',
        {
          props: {
            src: 'https://qiniushelves.jiachuangnet.com/shelf/img/%E6%9F%A5%E7%9C%8B%E8%AF%A6%E6%83%85.png',
            fit: 'cover',
            previewSrcList: imgList,
          },
          style: {
            width: '55px',
            height: '30px',
          },
        },
        {}
      )
    : h('div', {}, '-')
}
const _imgRenders = function (h, scope) {
  const { column, row } = scope
  const value = row[column.property]
  let imgList = []
  if (Array.isArray(value)) {
    try {
      imgList = value.filter((e) => e).map((e) => IMG_HOST + e)
    } catch (e) {}
  } else if ((value || '').includes(','))
    imgList = value
      .split(',')
      .filter((e) => e)
      .map((e) => IMG_HOST + e)
  else if (value) imgList.push(IMG_HOST + value)
  return imgList.length
    ? h(
        'el-image',
        {
          props: {
            src: imgList.toString(),
            fit: 'cover',
            previewSrcList: imgList,
          },
          style: {
            width: '55px',
            height: '30px',
          },
        },
        {}
      )
    : h('div', {}, '-')
}

export const PaymentList = [
  // sortIndex,
  { label: '订单ID', prop: 'orderId', minWidth: widthssl },
  { label: '回款金额', prop: 'amount', minWidth: widthssl },
  // {
  //   label: '回款截图',
  //   prop: 'prove',
  //   minWidth: widthdf,
  //   fixed: 'right',
  //   render: _imgRender,
  // },
]

const commonOrder = [
  // sortIndex,
  {
    label: '类型',
    prop: 'orderTYpe',
    // fixed:'left',
    minWidth: '60px',
    render: function (h, scope) {
      const { column, row } = scope
      return h(
        'div',
        {
          style: {
            color: row.orderType == 2 ? colorOrange : colorBlue,
          },
        },
        row.orderType == 2 ? '老店升级' : '新增店铺'
      )
    },
  },
  {
    label: '',
    prop: 'isPerSale',
    minWidth: '60px',
    render: function (h, scope) {
      const { row } = scope
      let text = ''
      let color = ''

      switch (row.isPerSale) {
        case 2:
          text = '正式单'
          color = colorOrange
          break
        case 1:
          text = '预售单'
          color = colorBlue
          break
        case 0:
        default:
          text = ''
          color = '#999' // 默认灰色
      }

      return h(
        'div',
        {
          style: {
            color: color,
          },
        },
        text
      )
    },
  },
  {
    label: '订单状态',
    prop: 'lockInventory',
    // fixed:'left',
    minWidth: '60px',
    render: function (h, scope) {
      const { column, row } = scope
      return h(
        'div',
        {
          style: {
            color: row.lockInventory == 2 ? colorBlue : colorOrange,
          },
        },
        row.lockInventory == 2 ? '已确认' : '未确认'
      )
    },
  },
  {
    label: '材料收款是否到账',
    prop: 'materialPayMoneyStatus',
    // fixed:'left',
    minWidth: '140px',
    render: function (h, scope) {
      const { column, row } = scope
      return h(
        'div',
        {
          style: {
            color: row.materialPayMoneyStatus == 1 ? colorBlue : colorOrange,
          },
        },
        row.lockInventory == 1 ? '已收款' : '未收款'
      )
    },
  },
  {
    label: '货架收款是否到账',
    prop: 'shelfPayMoneyStatus',
    // fixed:'left',
    minWidth: '140px',
    render: function (h, scope) {
      const { column, row } = scope
      return h(
        'div',
        {
          style: {
            color: row.shelfPayMoneyStatus == 1 ? colorBlue : colorOrange,
          },
        },
        row.shelfPayMoneyStatus == 1 ? '已收款' : '未收款'
      )
    },
  },
  {
    label: '是否欠款',
    prop: 'isDebt',
    minWidth: '60px',
    render: function (h, scope) {
      const { column, row } = scope
      const actions = []
      if (row.isDebt == 0 || !row.isDebt)
        actions.unshift(
          _h.call(
            this,
            h,
            row.isDebt == 1 ? colorBlue : colorOrange,
            'getIsDebt',
            row.isDebt == 1 ? '已结清' : '欠款'
          )
        )
      else actions.unshift(row.isDebt == 1 ? '已结清' : '欠款')
      return h('div', actions)
    },
  },
  {
    label: '卡游层板',
    prop: 'isKaYou',
    // fixed:'left',
    minWidth: '60px',
    render: function (h, scope) {
      const { column, row } = scope
      return h(
        'div',
        {
          style: {
            color: row.isKaYou == 1 ? colorBlue : colorOrange,
          },
        },
        row.isKaYou == 1 ? '是' : '否'
      )
    },
  },
  {
    label: 'ID',
    prop: 'id',
    minWidth: '60px',
    render: function (h, scope) {
      const { column, row } = scope
      return h('div', {}, row?.orderId || row[column.property])
    },
  },
  { label: '订单名称', prop: 'storeName', minWidth: '100px' },
  { label: '发起人', prop: 'creatorName', minWidth: '60px' },
  { label: '发货日期', prop: 'deliveryDate', minWidth: '82px' },
  {
    label: '营业区原始图',
    prop: 'storeImgs',
    minWidth: '65px',
    render: _imgRender,
  },
  {
    label: '营业区转化图',
    prop: 'cadImg',
    minWidth: '65px',
    render: _imgRender,
  },
  {
    label: '仓库原始图',
    prop: 'storageOriginImg',
    minWidth: '65px',
    render: _imgRender,
  },
  {
    label: '仓库转化图',
    prop: 'storageImg',
    minWidth: '65px',
    render: _imgRender,
  },
  {
    label: '营业区报价图',
    prop: 'goodsOfferImg',
    minWidth: '65px',
    render: _imgRender,
  },
  {
    label: '仓储区报价图',
    prop: 'storageOfferImg',
    minWidth: '65px',
    render: _imgRender,
  },
  { label: '拣货货架数量', prop: 'jhGoodsCount', minWidth: '95px' },
  { label: '安装货架数量', prop: 'azGoodsCount', minWidth: '95px' },
  { label: '发货地址', prop: 'address', minWidth: '120px' },
  { label: '距离/公里', prop: 'distance', minWidth: '120px' },
  { label: '面积/平方', prop: 'storeArea', minWidth: '120px' },
  { label: '材料付款方式', prop: 'paymentMethodName', minWidth: '120px' },
  { label: '货架付款方式', prop: 'goodsPaymentMethodName', minWidth: '120px' },
  { label: '安装总成本', prop: 'installationCost', minWidth: '120px' },
  {
    label: '总成本/元',
    prop: 'id',
    minWidth: '150px',
    render: function (h, scope) {
      const { column, row } = scope
      const actions = [
        _h.call(
          this,
          h,
          colorGrey,
          '1',
          '安装(含距离)：' + (row.installationCost || 0)
        ),
        _h.call(this, h, colorGrey, '2', '拣货：' + (row.jhCost || 0)),
        _h.call(this, h, colorGrey, '3', '装车：' + (row.zcCost || 0)),
        _h.call(this, h, colorGrey, '4', '距离：' + (row.distanceCost || 0)),
        _h.call(this, h, colorGrey, '5', '卸车：' + (row.xcCost || 0)),
        _h.call(this, h, colorBlue, '6', '总提成：' + (row.totalCost || 0)),
      ]
      return h(
        'div',
        {
          style: {
            display: 'flex',
            flexWrap: 'wrap',
          },
        },
        actions
      )
    },
  },
  { label: '客户联系方式', prop: 'customPhone', minWidth: '100px' },
  { label: '报价单运费', prop: 'expressCharge', minWidth: '100px' },
  createdColumn,
  ...(authority.includes(294)
    ? [{ label: '应收金额', prop: 'totalAmount', minWidth: widthxs }]
    : []),
  ...(authority.includes(293)
    ? [{ label: '已回款总额', prop: 'totalPayment', minWidth: '70px' }]
    : []),

  {
    label: '报价单转换金额',
    prop: 'quotationImgMoney',
    minWidth: '80px',
    render: function (h, scope) {
      const { row } = scope
      let valtext = row.quotationImgMoney
      let text = null
      if (valtext == null || valtext === '') {
        text = '-'
      } else if (isNaN(Number(valtext))) {
        text = '-'
      } else {
        text = Number((Number(valtext) / 10000).toFixed(5))
      }
      return h(
        'div',
        {
          style: {
            color: '#999',
          },
        },
        text
      )
    },
  },
  {
    label: '货架录入实付金额',
    prop: 'payMoney',
    minWidth: '80px',
    render: function (h, scope) {
      const { row } = scope
      let valtext = row.payMoney
      let text = null
      if (valtext == null || valtext === '') {
        text = '-'
      } else if (isNaN(Number(valtext))) {
        text = '-'
      } else {
        text = Number((Number(valtext) / 10000).toFixed(5))
      }
      return h(
        'div',
        {
          style: {
            color: '#999',
          },
        },
        text
      )
    },
  },
  {
    label: '报价-付款金额',
    prop: 'shelfPoorMoney',
    minWidth: '80px',
    render: function (h, scope) {
      const { row } = scope
      let valtext = row.shelfPoorMoney
      let text = null
      if (valtext == null || valtext === '') {
        text = '-'
      } else if (isNaN(Number(valtext))) {
        text = '-'
      } else {
        text = Number((Number(valtext) / 10000).toFixed(5))
      }
      return h(
        'div',
        {
          style: {
            color: '#999',
          },
        },
        text
      )
    },
  },
  {
    label: '材料下单金额',
    prop: 'materialPlaceMoney',
    minWidth: '80px',
    render: function (h, scope) {
      const { row } = scope
      let valtext = row.materialPlaceMoney
      let text = null
      if (valtext == null || valtext === '') {
        text = '-'
      } else if (isNaN(Number(valtext))) {
        text = '-'
      } else {
        text = Number((Number(valtext) / 10000).toFixed(5))
      }
      return h(
        'div',
        {
          style: {
            color: '#999',
          },
        },
        text
      )
    },
  },
  {
    label: '材料付款金额',
    prop: 'materialPayMoney',
    minWidth: '80px',
    render: function (h, scope) {
      const { row } = scope
      let valtext = row.materialPayMoney
      let text = null
      if (valtext == null || valtext === '') {
        text = '-'
      } else if (isNaN(Number(valtext))) {
        text = '-'
      } else {
        text = Number((Number(valtext) / 10000).toFixed(5))
      }
      return h(
        'div',
        {
          style: {
            color: '#999',
          },
        },
        text
      )
    },
  },
  {
    label: '材料差额',
    prop: 'materialPoorMoney',
    minWidth: '80px',
    render: function (h, scope) {
      const { row } = scope
      let valtext = row.materialPoorMoney
      let text = null
      if (valtext == null || valtext === '') {
        text = '-'
      } else if (isNaN(Number(valtext))) {
        text = '-'
      } else {
        text = Number((Number(valtext) / 10000).toFixed(5))
      }
      return h(
        'div',
        {
          style: {
            color: '#999',
          },
        },
        text
      )
    },
  },
  // {
  //   label: "省份",
  //   prop: "area",
  //   minWidth: "60px",
  //   render: function (h, scope) {
  //     const { column, row } = scope;
  //     const value = row[column.property];
  //     const { areaMap } = {
  //       43: "宁乡壹",
  //       42: "湖北",
  //       45: "广西",
  //       44: "广东",
  //       52: "贵州",
  //       53: '云南',
  //       46: "宁乡贰",
  //     };
  //     return h("div", {}, areaMap[value] || "-");
  //   },
  // },

  {
    label: '区域',
    prop: 'area',
    minWidth: '60px',
    render: function (h, scope) {
      const { column, row } = scope
      const value = row[column.property]
      return h('div', this.$store.state.areaMap[value] || '--')
    },
  },
  {
    label: '出库状态',
    prop: 'outStatus',
    minWidth: '70px',
    render: function (h, scope) {
      const { column, row } = scope
      const value = row[column.property]
      const outMap = {
        0: '待出库',
        1: '部分出库',
        2: '全部出库',
      }
      return h(
        'div',
        {
          style: {
            color: value ? (value == 1 ? colorBlue : colorOrange) : colorGrey,
          },
        },
        outMap[value]
      )
    },
  },
]

const commonOrderFilter = (
  arr = [
    'sortIndex',
    'id',
    'storeName',
    'deliveryDate',
    'address',
    'customPhone',
    'createdTime',
    'orderType',
  ]
) => {
  return commonOrder.filter((e) => arr.includes(e.prop))
}

export const OrderManage = [
  ...commonOrder,
  {
    label: 'CAD操作人',
    prop: 'cadName',
    minWidth: '60px',
    render: function (h, scope) {
      const { column, row } = scope

      const actions = []
      if (!row.cadName)
        actions.unshift(_h.call(this, h, colorGreen, 'getCadName', '认领'))
      else actions.unshift(row.cadName)
      return h('div', actions)
    },
  },
  {
    label: '操作',
    prop: 'actions',

    minWidth: '180px',
    render: function (h, scope) {
      const { column, row } = scope
      const status = row.status
      const actions = [
        _h.call(this, h, colorGrey, 'goodsDetail', '货架解析详情'),
        _h.call(this, h, colorGrey, 'storageDetail', '仓储解析详情'),
        _h.call(this, h, colorGrey, 'goodsOfferDetail', '营业区报价解析'),
        _h.call(this, h, colorGrey, 'storageOffer', '仓储区报价解析'),
        _h.call(this, h, colorGrey, 'exportContract', '下载合同'),
        _h.call(this, h, colorGrey, 'refund', '退款'),
        _h.call(this, h, colorGrey, 'refundDetail', '退款明细'),
        // _h.call(this, h, colorGreen, "confirmOrder", "确认订单"),
      ]
      // actions.unshift(_h.call(this, h, colorBlue, "export", "导出Excel"));
      if (authority.includes(202) && row.lockInventory == 1)
        actions.unshift(_h.call(this, h, colorGreen, 'addition', '杂项录入'))
      if (authority.includes(206))
        actions.unshift(_h.call(this, h, colorGrey, 'additionList', '杂项详情'))
      if (authority.includes(203))
        actions.unshift(_h.call(this, h, colorOrange, 'payment', '回款录入'))
      if (authority.includes(205))
        actions.unshift(_h.call(this, h, colorGrey, 'paymentList', '回款详情'))
      if (authority.includes(204) && row.isPerSale == 1)
        actions.unshift(_h.call(this, h, colorRed, 'area', '提交正式单'))
      if (authority.includes(207))
        // if (authority.includes(207) && row.outStatus === 0)
        actions.unshift(_h.call(this, h, colorGrey, 'edit', '录入货架信息'))
      if (authority.includes(208))
        actions.unshift(_h.call(this, h, colorRed, 'delete', '删除'))
      if (authority.includes(201) && row.lockInventory == 1)
        actions.unshift(_h.call(this, h, colorBlue, 'CAD', 'CAD上传'))
      if (authority.includes(177))
        actions.unshift(_h.call(this, h, colorGreen, 'costs', '成本导出'))
      if (authority.includes(211))
        actions.unshift(
          _h.call(this, h, colorGrey, 'exportWarehouseOrder', '报价单')
        )
      // 确认货架到款
      if (row.shelfPayMoneyStatus === 0) {
        actions.unshift(_h.call(this, h, colorRed, 'shelves', '货架确认到账'))
      }
      // 上传安装组数
      actions.unshift(
        _h.call(this, h, colorOrange, 'uploadCount', '上传安装组数')
      )
      // 确认材料到款
      if (row.materialPayMoneyStatus === 0) {
        actions.unshift(
          _h.call(this, h, colorRed, 'materialShouMoney', '材料确认到账')
        )
      }

      if (userName == 'admin' && row.contractImg)
        actions.unshift(
          _h.call(this, h, colorRed, 'cancelContract', '取消合同')
        )
      // 分割线 // 分割线// 分割线// 分割线// 分割线// 分割线// 分割线// 分割线// 分割线// 分割线// 分割线

      //换权限值  回滚库存304   确认订单303
      if (
        authority.includes(304) &&
        row.outStatus == 0 &&
        row.lockInventory == 2
      )
        actions.unshift(
          _h.call(this, h, colorOrange, 'returnInventory', '回滚库存')
        )
      if (
        authority.includes(303) &&
        row.outStatus == 0 &&
        row.lockInventory == 1 &&
        (row.cadImg || row.storageImg) &&
        row.isPerSale != 1
      )
        actions.unshift(_h.call(this, h, colorRed, 'confirmOrder', '确认订单'))
      return h(
        'div',
        {
          style: {
            display: 'flex',
            flexWrap: 'wrap',
          },
        },
        actions
      )
    },
  },
]

export const ClassifyDetail = [
  sortIndex,
  { label: '套件编码', prop: 'code', minWidth: widthxsl },
  { label: '套件名称', prop: 'name', minWidth: widthxsl },
  { label: '套件数量', prop: 'count', minWidth: widthxsl },
]

export const OrderWarehouse = [
  ...commonOrder.filter(
    (e) => !['totalAmount', 'totalPayment'].includes(e.prop)
  ),
  {
    label: '操作',
    prop: 'actions',
    fixed: 'right',
    minWidth: '260px',
    // fixed: "right",
    render: function (h, scope) {
      const { column, row } = scope
      const actions = [
        _h.call(this, h, colorGrey, 'goodsDetail', '货架解析详情'),
        _h.call(this, h, colorGrey, 'storageDetail', '仓储解析详情'),
      ]
      // actions.unshift(_h.call(this, h, colorBlue, "export", "导出Excel"));
      const { authority } = store.state
      actions.unshift(
        _h.call(this, h, colorGrey, 'newOrderStorageList', '仓储货架清单下载')
      )
      actions.unshift(
        _h.call(this, h, colorGrey, 'newOrderAdditionList', '杂项清单下载')
      )
      actions.unshift(
        _h.call(this, h, colorGrey, 'newOrderMaterialList', '货架清单下载')
      )
      actions.unshift(_h.call(this, h, colorOrange, 'installList', '操作列表'))
      actions.unshift(_h.call(this, h, colorOrange, 'install', '操作人员'))
      if (authority.includes(209))
        actions.unshift(_h.call(this, h, colorRed, 'delete', '删除'))
      if (row.outStatus != 2)
        actions.unshift(_h.call(this, h, colorBlue, 'out', '出库'))
      return h(
        'div',
        {
          style: {
            display: 'flex',
            flexWrap: 'wrap',
          },
        },
        actions
      )
    },
  },
]

export const StoreLedger = [
  { label: 'ID', prop: 'id', minWidth: widthdf },
  { label: '订单ID', prop: 'orderId', minWidth: widthdf },
  { label: '门店名称', prop: 'storeName', minWidth: widthdf },
  {
    label: '状态',
    prop: 'status',
    fixed: 'right',
    minWidth: widthdf,
    render: statusRenderMap({
      0: ['未完成', 'danger'],
      1: ['已完成', 'success'],
    }),
  },
  {
    label: '操作',
    prop: 'actions',
    minWidth: '150px',
    // fixed: "right",
    render: function (h, scope) {
      const { column, row } = scope
      const status = row.status
      const actions = []
      if (status != 1)
        actions.push(_h.call(this, h, colorGreen, 'Done', '确认完成'))
      return h(
        'div',
        {
          style: {
            display: 'flex',
            flexWrap: 'wrap',
          },
        },
        actions
      )
    },
  },
]

export const AreaLedger = [
  { label: 'ID', prop: 'id', minWidth: widthdf },
  {
    label: '省份',
    prop: 'area',
    minWidth: widthdf,
    render: function (h, scope) {
      const { column, row } = scope
      const value = row[column.property]
      const { areaMap } = store.state
      return h('div', {}, areaMap[value] || '-')
    },
  },
  { label: '金额', prop: 'amount', minWidth: widthdf },
  { label: '费用类型', prop: 'type', minWidth: widthdf },
  // { label: "备注", prop: "remark", minWidth: widthxsl },
  { label: '图片', prop: 'imgs', minWidth: widthxsl, render: _imgRender },
  createdColumn,
  updatedColumn,
]

export const OrderAftersale = [
  ...commonOrderFilter(),
  {
    label: '售后原因',
    prop: 'afterSaleTypeText',
    minWidth: '240px',
  },
  {
    label: '售后备注',
    prop: 'remark',
    minWidth: '280px',
  },
  {
    label: '售后图片',
    prop: 'preSalesImg',
    minWidth: widthdf,
    render: _imgRender,
  },
  { label: '售后人员', prop: 'afterSales', minWidth: widthxl },
  {
    label: '售后完成备注',
    prop: 'finishRemark',
    minWidth: widthxl,
  },
  // {
  //   label: "售后完成图片",
  //   prop: "afterSalesImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  // { label: "发车金额", prop: "departFee", minWidth: widthxsl },
  // {
  //   label: "发车金额截图",
  //   prop: "departImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  // { label: "安装费用", prop: "installFee", minWidth: widthxsl },
  // {
  //   label: "安装费用截图",
  //   prop: "installImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  // { label: "安装住宿费用", prop: "hotelFee", minWidth: widthxsl },
  // {
  //   label: "安装住宿费用截图",
  //   prop: "hotelImg",
  //   minWidth: widthxl,
  //   render: _imgRender,
  // },
  // { label: "工作餐费用", prop: "foodFee", minWidth: widthxsl },
  // {
  //   label: "工作餐费用截图",
  //   prop: "foodImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  // { label: "交通费用", prop: "trafficFee", minWidth: widthxsl },
  // {
  //   label: "交通费用截图",
  //   prop: "trafficImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  {
    label: '状态',
    prop: 'status',
    minWidth: widthdf,
    fixed: 'right',
    render: statusRender(AFTERSALE_TAG),
  },
  {
    label: '操作',
    prop: 'actions',
    // fixed: "right",
    minWidth: widthxxl,
    render: function (h, scope) {
      const { column, row } = scope
      const status = row.status
      const actions = [_h.call(this, h, colorGrey, 'detail', '产品详情')]
      if (status == 0 && authority.includes(295))
        actions.unshift(_h.call(this, h, colorGreen, 'done', '确认完成'))
      if (authority.includes(179))
        actions.push(_h.call(this, h, colorRed, 'delete', '删除'))
      return h('div', {}, actions)
    },
  },
]

export const AdditionList = [
  sortIndex,
  { label: '产品ID', prop: 'id', minWidth: widthxl },
  { label: '产品编码', prop: 'productCode', minWidth: widthdf },
  { label: '产品名称', prop: 'productName', minWidth: widthxsl },
  { label: '规格', prop: 'norms', minWidth: widthdf },
  { label: '单位', prop: 'unit', minWidth: widthdf },
  { label: '颜色', prop: 'colour', minWidth: widthdf },
  // { label: "单价", prop: "price", minWidth: widthdf },
  { label: '数量', prop: 'count', minWidth: widthdf, fixed: 'right' },
]

export const AfterSaleDetail = AdditionList

export const InstallList = [
  sortIndex,
  { label: '安装人员', prop: 'installers', minWidth: widthxl },
  // { label: "发车金额", prop: "departFee", minWidth: widthxsl },
  // {
  //   label: "发车金额截图",
  //   prop: "departImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  // { label: "安装费用", prop: "installFee", minWidth: widthxsl },
  // {
  //   label: "安装费用截图",
  //   prop: "installImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  // { label: "安装住宿费用", prop: "hotelFee", minWidth: widthxsl },
  // {
  //   label: "安装住宿费用截图",
  //   prop: "hotelImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  // { label: "工作餐费用", prop: "foodFee", minWidth: widthxsl },
  // {
  //   label: "工作餐费用截图",
  //   prop: "foodImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
  // { label: "交通费用", prop: "trafficFee", minWidth: widthxsl },
  // {
  //   label: "交通费用截图",
  //   prop: "trafficImg",
  //   minWidth: widthdf,
  //   render: _imgRender,
  // },
]

export const OrderExtra = [
  sortIndex,
  // { label: "订单ID", prop: "id", minWidth: widthxxl },
  // { label: "订单名称", prop: "orderName", minWidth: widthxsl },
  { label: '售后金额', prop: 'fee', minWidth: widthdf },
  {
    label: '售后理由',
    prop: 'reason',
    minWidth: widthxsl,
    render: statusRender(EXTRA_TAG),
  },
  { label: '售后备注', prop: 'remark', minWidth: widthxsl, showTip: true },
  { label: '创建人', prop: 'creatorName', minWidth: widthdf },
  createdColumn,
  // updatedColumn,
  {
    label: '订单状态',
    prop: 'status',
    minWidth: widthsm,
    fixed: 'right',
    render: statusRender(EXTRA_ORDER_STATUS, EXTRA_ORDER_TAG_STATUS),
  },
  {
    label: '操作',
    prop: 'actions',
    // fixed: "right",
    minWidth: widthxxl,
    render: function (h, scope) {
      const { column, row } = scope
      const status = row.status
      const actions = [_h.call(this, h, colorGrey, '0', '查看产品')]
      if (status == 0) {
        actions.unshift(
          _h.call(this, h, colorRed, '-1', '拒绝'),
          _h.call(this, h, colorGreen, '1', '通过')
        )
      }
      return h('div', {}, actions)
    },
  },
]

export const ExbandColumn = [
  sortIndex,
  { label: '订单ID', prop: 'id', minWidth: widthxxl },
  { label: '订单名称', prop: 'orderName', minWidth: widthxsl },
  { label: '售后金额', prop: 'fee', minWidth: widthdf },
  {
    label: '售后理由',
    prop: 'reason',
    minWidth: widthxsl,
    render: statusRender(EXTRA_TAG),
  },
  { label: '售后备注', prop: 'remark', minWidth: widthxsl, showTip: true },
  { label: '创建人', prop: 'creatorName', minWidth: widthdf },
  createdColumn,
  // updatedColumn,
  {
    label: '订单状态',
    prop: 'status',
    minWidth: widthsm,
    render: statusRender(EXTRA_ORDER_STATUS, EXTRA_ORDER_TAG_STATUS),
  },
]

export const OrderInstall = [
  sortIndex,
  { label: '订单ID', prop: 'id', minWidth: widthxxl },
  { label: '订单名称', prop: 'orderName', minWidth: widthxsl },
  goodsFeeColumn,
  installFeeColumn,
  hotelFeeColumn,
  trafficFeeColumn,
  otherFeeColumn,
  {
    label: '报装人',
    prop: 'installers',
    minWidth: widthdf,
    render: function (h, scope) {
      const { column, row } = scope
      return h('span', {}, row[column.property].join('、'))
    },
  },
  { label: '报装备注', prop: 'description', minWidth: widthxsl, showTip: true },
  { label: '创建人', prop: 'creatorName', minWidth: widthdf },
  createdColumn,
  // updatedColumn,
]

export const OrderFlow = [
  sortIndex,
  { label: '订单编号', prop: 'orderId', minWidth: widthxxl },
  { label: '订单名称', prop: 'orderName', minWidth: widthxsl },
  { label: '创建人', prop: 'creatorName', minWidth: widthdf },
  createdColumn,
  // updatedColumn,
  {
    label: '订单状态',
    prop: 'status',
    minWidth: widthsm,
    fixed: 'right',
    render: statusRender(ORDER_STATUS, ORDER_TAG_STATUS),
  },
]

export const InventoryWarn = [
  sortIndex,
  areaColumn,
  { label: '产品编码', prop: 'productCode', minWidth: widthdf },
  { label: '产品名称', prop: 'productName', minWidth: widthxsl },
  // { label: "套件", prop: "dirName", minWidth: widthxsl },
  { label: '规格', prop: 'norms', minWidth: widthdf },
  { label: '单位', prop: 'unit', minWidth: widthdf },
  { label: '颜色', prop: 'colour', minWidth: widthdf },
  // { label: '单价', prop: 'price', minWidth: widthdf },
  createdColumn,
  updatedColumn,
  inventoryColumn,
]

let saleKeys = []
let saleAction = [
  {
    label: '操作',
    prop: 'actions',
    minWidth: 100,
    // fixed: "right",
    render: function (h, scope) {
      const actions = [
        _h.call(this, h, colorGrey, 'modifyWarning', '修改预警值'),
      ]
      if (userName == 'admin') {
        actions.push(_h.call(this, h, colorBlue, 'modifyCount', '修改库存')) //仓库主管不可以修改库存
      }
      return h('div', {}, actions)
    },
  },
  // {
  //   label: "修改库位",
  //   prop: "editPosition",
  //   minWidth: widthdf,
  //   // fixed: "right",
  //   render: function (h, scope) {
  //     return _h.call(this, h, colorGreen, "modifyWarePosition", "修改库位");
  //   },
  // },
]
if ((authority || []).includes(191))
  saleKeys = [
    { label: '成本价', prop: 'price', minWidth: widthdf },
    { label: '售价', prop: 'salePrice', minWidth: widthdf },
  ]

if ((authority || []).includes(5)) saleAction = []

export const InventoryDetail = [
  sortIndex,
  areaColumn,
  // { label: "库位", prop: "warehousePosition", minWidth: widthdf },
  { label: '产品编码', prop: 'productCode', minWidth: widthdf },
  { label: '产品名称', prop: 'productName', minWidth: widthxsl },
  // { label: "套件", prop: "dirName", minWidth: widthxsl },
  // {
  //   label: "套件",
  //   prop: "directorys",
  //   minWidth: '200',
  //   render: function (h, scope) {
  //     const { column, row } = scope;
  //     const value = (row[column.property] || []).map((e) => e.name);
  //     let data = Ray.duplicate(value)
  //     return h("span", {}, data.join("、"));
  //   },
  // },
  { label: '规格', prop: 'norms', minWidth: widthdf },
  { label: '单位', prop: 'unit', minWidth: widthdf },
  { label: '颜色', prop: 'colour', minWidth: widthdf },
  {
    label: '预警值',
    prop: 'warningNum',
    minWidth: widthdf,
    render: function (h, scope) {
      const { column, row } = scope
      return h('div', (row.exigencyNum || 0) + '-' + row.warningNum)
    },
  },
  {
    label: '库存状态',
    prop: 'warningNum',
    minWidth: widthdf,
    render: function (h, scope) {
      const { column, row } = scope
      return h(
        'div',
        {
          style: {
            color:
              row.stockStatus === 1
                ? '#000000'
                : row.stockStatus === 2
                ? colorOrange
                : row.stockStatus === 3
                ? colorRed
                : colorGreen,
          },
        },
        row.stockStatus === 1
          ? '正常'
          : row.stockStatus === 2
          ? '警告'
          : row.stockStatus === 3
          ? '紧急'
          : '未知状态'
      )
    },
  },
  ...saleKeys,
  createdColumn,
  updatedColumn,
  inventoryColumn,
  ...saleAction,
]
export const ExtraListColumn = [
  sortIndex,
  { label: '产品ID', prop: 'id', minWidth: widthxl },
  { label: '产品编码', prop: 'productCode', minWidth: widthdf },
  { label: '产品名称', prop: 'productName', minWidth: widthxsl },
  { label: '规格', prop: 'norms', minWidth: widthdf },
  { label: '单位', prop: 'unit', minWidth: widthdf },
  { label: '颜色', prop: 'colour', minWidth: widthdf },
  // { label: '单价', prop: 'price', minWidth: widthdf },
  { label: '数量', prop: 'count', minWidth: widthdf, fixed: 'right' },
]

export const InventoryRecordDetail = [
  sortIndex,
  { label: '产品ID', prop: 'id', minWidth: widthxl },
  { label: '产品编码', prop: 'productCode', minWidth: widthdf },
  { label: '产品名称', prop: 'productName', minWidth: widthxsl },
  { label: '规格', prop: 'norms', minWidth: widthdf },
  { label: '单位', prop: 'unit', minWidth: widthdf },
  { label: '颜色', prop: 'colour', minWidth: widthdf },
  // { label: '单价', prop: 'price', minWidth: widthdf },
  { label: '数量', prop: 'count', minWidth: widthdf, fixed: 'right' },
]

export const ProductManage = [
  sortIndex,
  { label: '产品ID', prop: 'id', minWidth: widthxl },
  { label: '产品编码', prop: 'productCode', minWidth: widthdf },
  { label: '产品名称', prop: 'productName', minWidth: widthxsl },
  // {
  //   label: "套件",
  //   prop: "directorys",
  //   minWidth: widthxsl,
  //   render: function (h, scope) {
  //     const { column, row } = scope;
  //     const value = (row[column.property] || []).map((e) => e.name);
  //     let data = Ray.duplicate(value)
  //     return h("span", {}, data.join("、"));
  //   },
  // },
  { label: '规格', prop: 'norms', minWidth: widthdf },
  { label: '单位', prop: 'unit', minWidth: widthdf },
  { label: '颜色', prop: 'colour', minWidth: widthdf },
  // { label: '单价', prop: 'price', minWidth: widthdf },
  { label: '说明', prop: 'description', width: widthxsl, showTip: true },
  {
    label: '图片',
    prop: 'productImgStr',
    minWidth: widthxsl,
    render: _imgRenders,
  },
  createdColumn,
  updatedColumn,
  {
    label: '状态',
    prop: 'materialStatus',
    minWidth: widthsm,
    fixed: 'right',
    render: statusRender(PRODUCT_STATUS),
  },
  {
    label: '操作',
    prop: 'actions',
    minWidth: '140px',
    // fixed: "right",
    render: function (h, scope) {
      const { column, row } = scope
      const status = row.materialStatus
      return h('div', {}, [
        _h.call(this, h),
        status == 0
          ? _h.call(this, h, colorBlue, 'on', '上架')
          : _h.call(this, h, colorOrange, 'off', '下架'),
        // _h.call(this, h, colorGreen, "qrcode", "库存码"),
        _h.call(this, h, colorRed, 'delete', '删除'),
      ])
    },
  },
]

export const InventoryRecord = [
  sortIndex,
  areaColumn,
  // { label: "产品编码", prop: "productCode", minWidth: widthdf },
  // { label: "产品名称", prop: "productName", minWidth: widthxsl },
  // { label: "套件", prop: "dirName", minWidth: widthdf },
  // { label: "规格", prop: "norms", minWidth: widthdf },
  // { label: "单位", prop: "unit", minWidth: widthdf },
  // { label: "颜色", prop: "colour", minWidth: widthdf },
  // { label: "单价", prop: "price", minWidth: widthdf },
  { label: '订单号', prop: 'orderId', minWidth: widthdf },
  { label: '门店名称', prop: 'storeName', minWidth: widthdf },
  { label: '拣货人员', prop: 'sorter', minWidth: widthdf },
  { label: '操作人', prop: 'creatorName', minWidth: widthxsl },
  createdColumn,
  updatedColumn,
  // {label: "采购单名", prop: "purchaseName", minWidth: widthxsl},
  {
    label: '采购单图',
    prop: 'pimg',
    minWidth: widthdf,
    render: _imgRenders,
  }, // inventoryColumn,
  {
    label: '发车照片',
    prop: 'deliveryImg',
    minWidth: widthdf,
    render: _imgRenders,
  },
  {
    label: '送货单图',
    prop: 'listImg',
    minWidth: widthdf,
    render: _imgRender,
  },
  {
    label: '状态',
    prop: 'status',
    minWidth: widthsm,
    fixed: 'right',
    render: statusRender(INOUT_STATUS, INOUT_TAG_STATUS),
  },
  {
    label: '操作',
    prop: 'actions',
    minWidth: '100px',
    // fixed: "right",
    render: function (h, scope) {
      const { column, row } = scope
      const status = row.status
      return h('div', {}, [
        status == 0
          ? _h.call(this, h, colorGreen, 'detail', '出库清单')
          : _h.call(this, h, colorBlue, 'detail', '入库清单'),
      ])
    },
  },
]

export const ClassifyManage = [
  sortIndex,
  { label: '套件名称', prop: 'name', minWidth: widthxsl },
  // { label: '套件价格', prop: 'salePrice', minWidth: widthxsl },
  { label: '创建人', prop: 'creatorName', minWidth: widthdf },
  createdColumn,
  updatedColumn,
  {
    label: '状态',
    prop: 'status',
    minWidth: widthsm,
    fixed: 'right',
    render: statusRender(),
  },
  {
    label: '操作',
    prop: 'actions',
    minWidth: widthlg,
    // fixed: "right",
    render: function (h, scope) {
      const { column, row } = scope
      const status = row.status
      return h('div', {}, [
        _h.call(this, h),
        // status == 0
        //   ? _h.call(this, h, colorBlue, "on", "开启")
        //   : _h.call(this, h, colorOrange, "off", "禁用"),
        _h.call(this, h, colorRed, 'delete', '删除'),
      ])
    },
  },
]

export const AccountManage = [
  sortIndex,
  { label: '姓名', prop: 'userName', minWidth: widthdf },
  { label: '手机号码', prop: 'mobile', minWidth: widthdf },
  {
    label: '角色',
    prop: 'role.name',
    minWidth: widthdf,
  },
  // { label: "上级", prop: "leaderName", minWidth: widthdf },
  createdColumn,
  updatedColumn,
  {
    label: '操作',
    prop: 'actions',
    // fixed: "right",
    minWidth: widthxxl,
    action: [
      {
        text: '修改',
        type: 'text',
        options: 'edit',
      },
      // {
      //   text: "修改密码",
      //   type: "text",
      //   options: "editPsd",
      //   style: {
      //     color: colorOrange,
      //   },
      // },
      {
        text: '删除',
        type: 'text',
        options: 'delete',
        style: {
          color: colorRed,
        },
      },
    ],
  },
]

export const RoleManage = [
  { label: '角色ID', prop: 'id', minWidth: widthdf },
  { label: '角色权限', prop: 'permission', minWidth: widthdf },
  { label: '角色名', prop: 'name', minWidth: widthdf },
  { label: '角色描述', prop: 'description', minWidth: widthdf },
  createdColumn,
  updatedColumn,
  {
    label: '状态',
    prop: 'status',
    minWidth: widthsm,
    fixed: 'right',
    render: statusRender(),
  },
  {
    label: '操作',
    prop: '',
    // fixed: "right",
    action: [
      {
        text: '修改',
        type: 'text',
        options: 'edit',
      },
    ],
  },
]

export const Finance = [
  ...commonOrderFilter(),
  { label: '已支付总金额', prop: 'payAmount', minWidth: widthsm },
  {
    label: '付款凭证',
    prop: 'payVoucher',
    minWidth: widthdf,
    render: _imgRender,
  },
  { label: '驳回备注', prop: 'remark', width: widthssl },
  ...OrderAftersale.filter((e) =>
    [
      'departFee',
      'departImg',
      'installFee',
      'installImg',
      'hotelFee',
      'hotelImg',
      'foodFee',
      'foodImg',
      'trafficFee',
      'trafficImg',
    ].includes(e.prop)
  ),
  {
    label: '订单类型',
    prop: 'type',
    minWidth: widthsm,
    fixed: 'right',
    render: statusRender(FINANCE_TYPE_STATUS, FINANCE_TYPE_TAG_STATUS),
  },
  {
    label: '操作',
    prop: 'actions',
    minWidth: widthdf,
    // fixed: "right",
    render: function (h, scope) {
      const { column, row } = scope
      const status = row.status
      const actions = []
      if (authority.includes(184) && status == 0)
        actions.push(_h.call(this, h, colorBlue, 'financeDoneRef', '付款完成'))
      if (authority.includes(183) && status == 0)
        actions.push(
          _h.call(this, h, colorOrange, 'finaceRefuseRef', '付款驳回')
        )
      if (authority.some((e) => [182, 181, 180].includes(e)))
        actions.push(_h.call(this, h, colorRed, 'delete', '删除'))
      return h(
        'div',
        {
          style: {
            display: 'flex',
            flexWrap: 'wrap',
          },
        },
        actions
      )
    },
  },
]

let newFinance = Finance.filter((e) => e.prop != 'actions')
newFinance.push({
  label: '操作',
  prop: 'actions',
  // fixed: "right",
  minWidth: widthsm,
  render: function (h, scope) {
    const { column, row } = scope
    const status = row.status
    const actions = []
    actions.push(_h.call(this, h, colorRed, 'updateFinanceRef', '编辑'))
    return h('div', {}, actions)
  },
})

export const FinanceReject = newFinance
